﻿ //十六进制代码转RGB函数

function hexToRgb(hex) {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);    
    return result ? {        
        r: parseInt(result[1], 16),               
        g: parseInt(result[2], 16),        
        b: parseInt(result[3], 16)    
    } : null;     
}

function xia1(a){
	var c = hexToRgb(a);
	//alert(c.r);
if ( app.documents.length > 0 ) { // Define the new color 
    var newRGBColor = new RGBColor();
newRGBColor.red = c.r; newRGBColor.green = c.g; newRGBColor.blue = c.b; app.activeDocument.defaultFillColor = newRGBColor;
}

	//app.foregroundColor.rgb.red = c.r;
	//app.foregroundColor.rgb.green = c.g;
	//app.foregroundColor.rgb.blue = c.b;
		
}

function xia2(a){
	app.activeDocument.defaultStroked=true;
	var c = hexToRgb(a);
	//alert(c.r);
if ( app.documents.length > 0 ) { // Define the new color 
    var newRGBColor = new RGBColor();
newRGBColor.red = c.r; newRGBColor.green = c.g; newRGBColor.blue = c.b; app.activeDocument.defaultStrokeColor = newRGBColor;
}

	
}

function shang1(kuang){
	if ( app.documents.length > 0 ) {
     var a= app.activeDocument.defaultFillColor ;
     //RGB模式下的判定
     if (a.red) {
     	if (a.red>=0&&a.red<16) {a1="0"+a.red.toString(16)}else{a1=(a.red).toString(16)};
     if (a.green>=0&&a.green<16) {a2="0"+a.green.toString(16)}else{a2=(a.green).toString(16)};
     if (a.blue>=0&&a.blue<16) {a3="0"+a.blue.toString(16)}else{a3=(a.blue).toString(16)};
     var kuang = a1+a2+a3;
     } 
     //CMYK模式下的判定
     else{
var c=Math.round(a.cyan);
var m=Math.round(a.magenta);
var y=Math.round(a.yellow);
var k=Math.round(a.black);
var a=Math.max(c,Math.max(m,y));
var maxval=Math.max(k,a);
var r = (k*c)/maxval;
var g = (k*m)/maxval;
var b = (k*y)/maxval; 
     var kuang = c+","+m+","+y+","+k+",";
     alert(kuang+"CMYK模式暂不支持")

    //return (""+padZero(color.toString(16)));
     };
     
     

     //var kuang= a1 +a2+a3;

     //alert(kuang);
     return kuang;
     

}
}

//去掉填充颜色
function qutian(){
	app.activeDocument.defaultFilled=false;
}

//去掉填充颜色
function qumiaobian(){
	app.activeDocument.defaultStroked=false;
}